// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import 'lib-flexible'
import Vant from 'vant';
import 'vant/lib/index.css';
import axios from "axios"
import VueCookies from 'vue-cookies'
Vue.use(VueCookies)
import store from './store'


Vue.use(Vant);
Vue.config.productionTip = false
// import Vconsole from 'vconsole';
// new Vconsole();

router.beforeEach(( to, from, next ) => {
  let _token = localStorage.getItem('customerwx');
  if (!_token) {//如果没有token,则让它授权
    if(getUrlParams('state')&&getUrlParams('state')!='STATE'){
      if(to.path === '/follow'){
        next()
      }else{
        next('/follow')
      }
    }else{
      if(to.path === '/login'||to.path === '/register'||to.path === '/wpass'||to.path === '/auth'||to.path === '/login2'||to.path === '/xiyi'||to.path === '/follow'){
        next()
      }else{
        next('/login')
      }
    }
  }else{
    if(getUrlParams('state')&&getUrlParams('state')!='STATE'){
      if(to.path === '/follow'||to.path === '/login'||to.path === '/register'||to.path === '/wpass'||to.path === '/auth'||to.path === '/login2'||to.path === '/xiyi' ){
        next()
      }else{
        next('/follow')
      }
    }else{
      next()
    }
  } 
});
function getUrlParams(name) {
  // 不传name返回所有值，否则返回对应值
  var url = window.location.search;
  if (url.indexOf("?") == 1) {
    return false;
  }
  url = url.substr(1);
  url = url.split("&");
  var name = name || "";
  var nameres;
  // 获取全部参数及其值
  for (var i = 0; i < url.length; i++) {
    var info = url[i].split("=");
    var obj = {};
    obj[info[0]] = decodeURI(info[1]);
    url[i] = obj;
  }
  // 如果传入一个参数名称，就匹配其值
  if (name) {
    for (var i = 0; i < url.length; i++) {
      for (const key in url[i]) {
        if (key == name) {
          nameres = url[i][key];
        }
      }
    }
  } else {
    nameres = url;
  }
  // 返回结果
  return nameres;
}
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
